import type { PayloadAction } from "@reduxjs/toolkit";
import { createSlice } from "@reduxjs/toolkit";

const appSlice = createSlice({
  name: "app",
  initialState: {
    // 控制左侧是否收起
    collapsed: false,
    msg: "hello",
  },
  reducers: {
    setCollapsed(state, action: PayloadAction<boolean>) {
      state.collapsed = action.payload;

      // if (action.payload) {
      //   // 存一份到 本地存储中
      //   localStorage.setItem("collapsed", action.payload);
      // } else {
      //   localStorage.removeItem("collapsed");
      // }

      // localStorage.setItem("collapsed", action.payload ? "true" : "");
    },
  },
});

// 具名解构导出 动作创建函数
export const { setCollapsed } = appSlice.actions;

// 必须，默认导出 reducer
export default appSlice.reducer;
